package com.xgpro.pc.studycentre.controller;

import com.xgpro.common.controller.BaseController;
import com.xgpro.common.exceptions.BusinessRuntimeException;
import com.xgpro.common.results.ResponseResult;
import com.xgpro.domain.studycentre.vo.PlanFront;
import com.xgpro.domain.studycentre.vo.PlanPCFront;
import com.xgpro.domain.studycentre.vo.PlanPCResult;
import com.xgpro.pc.studycentre.service.PlanPCService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author tx
 * @version 1.0
 * @date 2019/10/15 20:43
 */
@RestController
@RequestMapping("/planPC")
@CrossOrigin(allowCredentials="true")
public class PlanPCController  extends BaseController {
    @Autowired
    private PlanPCService planPCService;

    /**
     * 培训计划列表
     * @param planPCFront
     * @return
     */
    @RequestMapping("/qryPlanPCResult")
    public ResponseResult qryPlanPCResult(@RequestBody PlanPCFront planPCFront){
           return ResponseResult.ok(planPCService.qryPlanPCResult(planPCFront));
    }

    /**
     * 根据id删除培训计划
     * @param id
     * @return
     */
    @RequestMapping("/deleteByPlanId")
    public ResponseResult deleteByPlanId(Integer id){
        return ResponseResult.ok(planPCService.deleteByPlanId(id));
    }

    /**
     * 上传培训计划
     * @param planFront
     * @return
     * @throws IOException
     */
    @RequestMapping("/insertPlan")
    public ResponseResult insertPlan( PlanFront planFront) throws IOException{
        try{
            return ResponseResult.ok(planPCService.insertPlan(planFront));
        }catch (BusinessRuntimeException e){
            return ResponseResult.failure(e.getErrorCode(),e.getMessage());
        }
    }

    /**
     * 下载培训计划
     * @param id
     * @return
     */
    @RequestMapping("/downloadPlan")
    public ResponseResult downloadPlan(@RequestParam Integer id) throws Exception {
        return planPCService.downloadPlan(id);
    }

}
